<include file="Public/header" title="前台用户管理 - 企业安全响应与缺陷管理中心" users_status="open" member_color="#6164C1;"/>
<style>
/* The switch - the box around the slider */
.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}
 
/* Hide default HTML checkbox */
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
 
/* The slider */
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}
 
.slider:before {
  position: absolute;
  content: "";
  height: 15px;
  width: 19px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}
 
input:checked + .slider {
  background-color: #2196F3;
}
 
input:checked + .slider:before {
  -webkit-transform: translateX(26px);
  -ms-transform: translateX(26px);
  transform: translateX(26px);
}
 
/* Rounded sliders */
.slider.round {
  border-radius: 34px;
}
 
.slider.round:before {
  border-radius: 50%;
}

</style>
<div class="main-content">
    <div class="row">
        <div class="col-md-6">
            <a href="{:U('member/add')}" class="btn btn-success" style="margin : 2px 5px 5px 0px;">添加用户</a> 
            是否开启注册：
            <label class="switch">
			  <input type="checkbox"  id="toggle"  <?php echo ($setting == 1) ? 'checked' : ''; ?> >
			  <span class="slider round"></span>
			</label> 
			
        </div>
        <div class="col-md-6">
            <form action="{:U('member/index')}" method="post">
                <div class="form-group input-group">
                    <input type="text" class="form-control" name="key" value="{$search_key}" placeholder="输入用户名或者邮箱关键词搜索...">
                    <span class="input-group-btn">
                      <button class="btn btn-default" type="submit"><i class="fa fa-search"></i></button>
                    </span>
                </div>
            </form>
        </div>
    </div>
    

	<div class="no-more-tables">
    <table class="table m-b-0">
        <thead>
            <tr>
                <td>编号</td>
                <td>用户名</td>
                <td>邮箱</td>
                <td>注册时间</td>
                <td>上次登陆</td>
                <td>登陆IP</td>
                <td>用户等级</td>
                <td>用户状态</td>
                <td>积分</td>
                <td>安全币</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
        <foreach name="member" item="v">
            <tr>
                <td data-title="编号">{$v.id}</td>
                <td data-title="用户名">{$v.username}</td>
                <td data-title="邮箱">{$v.email}</td>
                <td data-title="注册时间">{$v.create_at|date="Y/m/d H:i:s",###}</td>
                <td data-title="上次登录">{$v.update_at|date="Y/m/d H:i:s",###}</td>
                <td data-title="登录IP">{$v.login_ip}</td>
                <td data-title="用户等级">
                    <if condition="$v.type eq 1"> <span class="label label-default">路人</span>
                    <elseif condition="$v.type eq 2"/><span class="label label-info">实习白帽子</span>
					<elseif condition="$v.type eq 3"/><span class="label label-success">普通白帽子</span>
                    <elseif condition="$v.type eq 4"/><span class="label label-danger">核心白帽子</span>
                    </if>
                </td> 
                <td data-title="用户状态"><if condition="$v.status eq 1">正常<else/><span style="color:red">禁用</span></if></td>
                <td data-title="积分">{$v.jifen}</td>
                <td data-title="安全币">{$v.jinbi}</td>
                <if condition="$v.status eq 1">	
                	<td data-title="操作"><a href="{:U('member/update?id=')}{$v.id}">编辑</a> | <a href="{:U('member/delete?id=')}{$v.id}&token={:session('token')}" style="color:red;" onclick="return confirm('删除后所有用户资料将清除!\n\n请确认!');">删除</a> | <a href="{:U('member/ban?id=')}{$v.id}&token={:session('token')}" style="color:red;" onclick="return confirm('禁用后用户将不能登陆前台!\n请确认!');">禁用</a></td>
            	<else/>
            		<td><a href="{:U('member/update?id=')}{$v.id}">编辑 </a>| <a href="{:U('member/delete?id=')}{$v.id}&token={:session('token')}" style="color:red;" onclick="return confirm('删除后所有用户资料将清除!\n请确认!');">删除</a> | <a href="{:U('member/ban?id=')}{$v.id}&token={:session('token')}" style="color:#50AD1E;"> 启用</a></td>
            	</if>
            </tr>
        </foreach>
        </tbody>
    </table>
</div>
    <div class="clearfix"></div>
    {$page}
</div>

<script> 
// 获取复选框和状态文本元素
const toggle = document.getElementById('toggle');
const statusText = document.getElementById('status');

// 添加点击事件监听器
toggle.addEventListener('change', function() { 
	const isChecked = $(this).is(':checked'); 
	var token = "{:session('token')}";
    $.ajax({
        type: 'POST',
        url: "{:U('member/register')}", // 替换为您的服务器端处理脚本
        data: { status: isChecked ? '1' : '0',
        		token: token}, 
        success: function(response) {
            console.log(response); // 服务器响应
        },
        error: function(xhr, status, error) {
            console.error('AJAX Error:', status, error);
        }
    });
}); 
</script>

<include file="Public/footer" />